<?
if(isset($_SESSION["loginConta"]))
    $username = $_SESSION["loginConta"];

if(isset($_SESSION["senhaConta"]))
    $senha = $_SESSION["senhaConta"];

if(!(empty($username) || empty($senha))) {

    require_once "../conta/contaBO.php";
    require_once "../conta/conta.php";

    $conta = new Conta();
    $conta->setLogin($username);
    $conta->setSenha($senha);

    $contaBO = new ContaBO();
    $conta = $contaBO->autenticar($conta);

    if($conta == null){
            session_destroy();
            $script ='<script language="javascript">location.href=\'login.php?erro=1\';</script>';
            echo $script;
            exit;
    }
    else if($conta->getCadastroConfirmado() == "N"){
            $script ='<script language="javascript">location.href=\'login.php?erro=3\';</script>';
            echo $script;
            exit;
    }
    
}
else{
    session_destroy();
            $script ='<script language="javascript">location.href=\'login.php?erro=2\';</script>';
            echo $script;
            exit;
}
?>